// 
// Copyright (C) 2006 Enterprise Distributed Technologies Ltd
// 
// www.enterprisedt.com
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Bug fixes, suggestions and comments should posted on 
// http://www.enterprisedt.com/forums/index.php

#region Change Log

// Change Log:
// 
// $Log: FTPTypes.cs,v $
// Revision 1.5  2006/10/04 08:05:02  hans
// Added ResumeOffset argument to BytesTransferredEventArgs.
//
// Revision 1.4  2006/08/09 07:49:20  hans
// Added setter for TransferEventArgs.LocalFilePath
//
// Revision 1.3  2006/07/31 08:02:26  hans
// Added region for each class and added PropertyOrderAttribute.
//
// Revision 1.2  2006/07/07 15:46:44  bruceb
// augment doco
//
// Revision 1.1  2006/06/19 13:00:12  bruceb
// extracted types into another file
//
// Revision 1.2  2006/06/16 12:14:48  bruceb
// added FTPMessageEventArgs etc
//
// Revision 1.1  2006/06/14 10:07:38  bruceb
// moved out of FTPClient
//
//

#endregion

#region Using

using System;
using System.IO;
using System.ComponentModel;

#endregion

namespace EnterpriseDT.Net.Ftp
{
	#region FTPMessageEventArgs and FTPMessageHandler

	/// <summary>
	/// Event args for ReplyReceived and CommandSent events
	/// </summary>    
	public class FTPMessageEventArgs : EventArgs
	{
		/// <summary>
		/// Constructor
		/// <param name="message"> 
		/// The message sent to or from the remote host
		/// </param>
		/// </summary>        
		public FTPMessageEventArgs(string message)
		{
			this.message = message;
		}

		/// <summary>
		/// Gets the message 
		/// </summary>   
		public string Message
		{
			get
			{
				return message;
			}
		}

		private string message;
	}

	/// <summary>
	/// Delegate used for ReplyReceived and CommandSent events
	/// </summary>
	public delegate void FTPMessageHandler(object sender, FTPMessageEventArgs e);

	#endregion

	#region BytesTransferredEventArgs and BytesTransferredHandler

	/// <summary>
	/// Event args for BytesTransferred event
	/// </summary>    
	public class BytesTransferredEventArgs : EventArgs
	{
		/// <summary>
		/// Constructor
		/// <param name="remoteFile">The name of the file being transferred.</param>
		/// <param name="byteCount">The current count of bytes transferred.</param>
		/// </summary>        
		public BytesTransferredEventArgs(string remoteFile, long fileSize, long byteCount, long resumeOffset)
		{
			this.remoteFile = remoteFile;
			this.fileSize = fileSize;
			this.byteCount = byteCount;
			this.resumeOffset = resumeOffset;
		}

		/// <summary>
		/// Constructor
		/// <param name="byteCount">The current count of bytes transferred.</param>
		/// </summary>        
		public BytesTransferredEventArgs(long byteCount)
		{
			this.byteCount = byteCount;
		}

		/// <summary>
		/// Gets the byte count.
		/// </summary>   
		public long ByteCount
		{
			get
			{
				return byteCount;
			}
		}

		/// <summary>
		/// Gets the byte count.
		/// </summary>   
		public long FileSize
		{
			get
			{
				return fileSize;
			}
		}

		/// <summary>
		/// If a transfer was resumed then this property will return the byte-offset from which
		/// the transfer starts.
		/// </summary>
		public long ResumeOffset
		{
			get
			{
				return resumeOffset;
			}
		}

		/// <summary>
		/// Name of the file.
		/// </summary>   
		public string RemoteFile
		{
			get
			{
				return remoteFile;
			}
		}

		private long byteCount;
		private long resumeOffset;
		private string remoteFile;
		private long fileSize;

	}

	/// <summary>
	/// Delegate used for the BytesTransferred event
	/// </summary>
	public delegate void BytesTransferredHandler(object sender, BytesTransferredEventArgs e);

	#endregion

	#region TransferEventArgs and TransferHandler

	/// <summary>
	/// Event args for TransferStarted/Complete
	/// </summary>    
	public class TransferEventArgs : EventArgs
	{
		/// <summary>
		/// Constructor
		/// </summary>        
		/// <param name="localStream"> 
		/// The stream being transferred to/from.
		/// </param>
		/// <param name="remoteFilename"> 
		/// The remote file name to be uploaded or downloaded
		/// </param>
		/// <param name="direction"> 
		/// Upload or download
		/// </param>
		/// <param name="transferType"> 
		/// ASCII or binary
		/// </param>
		public TransferEventArgs(Stream localStream, string remoteFilename, TransferDirection direction, FTPTransferType transferType)
		{
			this.localStream = localStream;
			this.remoteFilename = remoteFilename;
			this.direction = direction;
			this.transferType = transferType;
		}
		/// <summary>
		/// Constructor
		/// </summary>        
		/// <param name="localByteArray"> 
		/// The byte-array being transferred to/from.
		/// </param>
		/// <param name="remoteFilename"> 
		/// The remote file name to be uploaded or downloaded
		/// </param>
		/// <param name="direction"> 
		/// Upload or download
		/// </param>
		/// <param name="transferType"> 
		/// ASCII or binary
		/// </param>
		public TransferEventArgs(byte[] localByteArray, string remoteFilename, TransferDirection direction, FTPTransferType transferType)
		{
			this.localByteArray = localByteArray;
			this.remoteFilename = remoteFilename;
			this.direction = direction;
			this.transferType = transferType;
		}

		/// <summary>
		/// Constructor
		/// </summary>        
		/// <param name="localFilePath"> 
		/// Path of the local file to be uploaded or downloaded (<c>null</c> for <c>Stream</c> and <c>byte[]</c> transfers)
		/// </param>
		/// <param name="remoteFilename"> 
		/// The remote file name to be uploaded or downloaded
		/// </param>
		/// <param name="direction"> 
		/// Upload or download
		/// </param>
		/// <param name="transferType"> 
		/// ASCII or binary
		/// </param>
		public TransferEventArgs(string localFilePath, string remoteFilename, TransferDirection direction, FTPTransferType transferType)
		{
			this.localFilePath = localFilePath;
			this.remoteFilename = remoteFilename;
			this.direction = direction;
			this.transferType = transferType;
		}

		/// <summary>
		/// Gets the path of the local file.
		/// </summary>   
		public string LocalFilePath
		{
			get
			{
				return localFilePath;
			}
			set
			{
				localFilePath = value;
			}
		}

		/// <summary>
		/// Gets the stream being transferred to/from.
		/// </summary>   
		public Stream LocalStream
		{
			get
			{
				return localStream;
			}
		}

		/// <summary>
		/// Gets the byte-array being transferred to/from.
		/// </summary>   
		public byte[] LocalByteArray
		{
			get
			{
				return localByteArray;
			}
		}

		/// <summary>
		/// Gets the remote filename 
		/// </summary>   
		public string RemoteFilename
		{
			get
			{
				return remoteFilename;
			}
		}

		/// <summary>
		/// Gets the transfer direction 
		/// </summary>   
		public TransferDirection Direction
		{
			get
			{
				return direction;
			}
		}

		/// <summary>
		/// Gets the transfer type 
		/// </summary>   
		public FTPTransferType TransferType
		{
			get
			{
				return transferType;
			}
		}

		private Stream localStream;
		private byte[] localByteArray;
		private string localFilePath;
		private string remoteFilename;
		private TransferDirection direction;
		private FTPTransferType transferType;
	}

	/// <summary>
	/// Delegate used for TransferStarted and TransferComplete events
	/// </summary>
	public delegate void TransferHandler(object sender, TransferEventArgs e);

	#endregion

	#region TransferDirection

	/// <summary>
	/// Enumerates the possible transfer directions
	/// </summary>
	public enum TransferDirection
	{
		/// <summary>   
		/// Represents uploading a file
		/// </summary>
		UPLOAD = 1,

		/// <summary>   
		/// Represents downloading a file
		/// </summary>
		DOWNLOAD = 2
	}

	#endregion

	#region FTPTransferType

	/// <summary>  
	/// Enumerates the transfer types possible. We support only the two common types, 
	/// ASCII and Image (often called binary).
	/// </summary>
	public enum FTPTransferType
	{
		/// <summary>   
		/// Represents ASCII transfer type. As data is transferred, line terminator characters
		/// are translated into the local (client) platform's line terminator characters (CRLF for Windows
		/// platforms). For example, if transferring text files from a Unix server, line terminators will
		/// be converted from LF to CRLF.
		/// </summary>
		ASCII = 1,

		/// <summary>   
		/// Represents Image (or binary) transfer type. Files are transferred byte for byte
		/// without any conversion.
		/// </summary>
		BINARY = 2
	}

	#endregion

	#region PropertyOrderAttribute

	public class PropertyOrderAttribute : Attribute
	{
		private int order;

		public PropertyOrderAttribute(int order)
		{
			this.order = order;
		}

		public int Order
		{
			get { return order; }
			set { order = value; }
		}

	}

	#endregion
}
